const Router = require('koa-router');
let svgCaptcha = require('svg-captcha');

const router = new Router({
  prefix: '/captcha'
});

router.get('/getCaptcha', async (ctx) => {
  var captcha = svgCaptcha.create({
    inverse: false,
    fontSize: 56,
    noise: 1,
    width: 100,
    height: 40,
    size: 4,
    ignoreChars: '0oO1iIvVyY',
    background: '#fefefe',
    color: '#343434'
  });

  ctx.session.setCaptcha = captcha.text.toLowerCase();
  ctx.set('Content-Type', 'image/svg+xml');
  ctx.body = {
    status: 200,
    data: captcha.data,
    msg: '验证码生成成功'
  };
});

router.get('/getSmsCode', async (ctx) => {
  ctx.session.setSmsCode = "123456";
  ctx.body = {
    status: 200,
    msg: '短信验证码发送成功！'
  }
  console.log(ctx.session.setCaptcha);
});

module.exports = router;
